//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_getunitliste.sqf"
#include "x_setup.sqf"

__TRACE_1("_this","_this")

private ["_grptype","_how_many","_list","_one_man","_side","_side_char","_unitliste","_vehiclename","_varray"];
PARAMS_2(_grptype,_side);
_unitliste = [];_vehiclename = "";_varray = [];
_side_char = if (typeName _side == "STRING") then {
	switch (_side) do {case "OPFOR": {"E"};case "BLUFOR": {"W"};case "GUER": {"G"};case "CIV": {"W"};case "EAST": {"E"};case "WEST": {"W"};}
} else {
	switch (_side) do {case opfor: {"E"};case blufor: {"W"};case independent: {"G"};case civilian: {"W"};}
};
switch (_grptype) do {
	case "basic": {_list = missionNamespace getVariable format [QGVAR(allmen_%1),_side_char];_unitliste = _list call FUNC(RandomArrayVal)};
	case "specops": {_how_many = ceil random 5; if (_how_many < 2) then {_how_many = 2};_list = missionNamespace getVariable format [QGVAR(specops_%1),_side_char];_unitliste resize _how_many;for "_i" from 0 to _how_many - 1 do {_unitliste set [_i, _list call FUNC(RandomArrayVal)]}};
	case "artiobserver": {_unitliste = [missionNamespace getVariable format[QGVAR(arti_observer_%1),_side_char]]};
	case "sniper": {_unitliste = missionNamespace getVariable [format[QGVAR(snipers_%1),_side_char], ((missionNamespace getVariable format [QGVAR(allmen_%1),_side_char]) call FUNC(RandomArrayVal))]};
	case "heli": {_list = missionNamespace getVariable format [QGVAR(allmen_%1),_side_char];_unitliste = _list call FUNC(RandomArrayVal)};
	case "tank": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 0;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "bmp": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 1;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "brdm": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 2;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "shilka": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 3;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "uaz_mg": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 4;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "uaz_grenade": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 5;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "DSHKM": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 6;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "AGS": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 7;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "D30": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 8;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "uralfuel": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 9;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "uralrep": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 10;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "uralammo": {_varray = (missionNamespace getVariable format [QGVAR(veh_a_%1), _side_char]) select 11;_vehiclename = _varray call FUNC(RandomArrayVal)};
	case "civilian": {_unitliste resize 11; for "_i" from 0 to 10 do {_one_man = GVAR(civilians_t) call FUNC(RandomArrayVal);_unitliste set [_i,_one_man]}};
	case "sabotage": {_how_many = ceil random 11; if (_how_many < 6) then {_how_many = 6};_list = missionNamespace getVariable format [QGVAR(sabotage_%1),_side_char];_unitliste resize _how_many; for "_i" from 0 to _how_many - 1 do {_unitliste set [_i, _list call FUNC(RandomArrayVal)]}};
};
[_unitliste, _vehiclename]